from langchain.prompts import PromptTemplate
import prompt_fromat_Feats
from langchain.prompts.chat import (
    ChatPromptTemplate,SystemMessagePromptTemplate,HumanMessagePromptTemplate)
'''
一：
1:定义模版串
template = "xxxxx{p1}xxxx{p2}"
2:模版串转化为提示模版
prompt = PromptTemplate.form_template(template)
3:格式化模版中参数
prompt.format(template=template, p1=p1, p2=p2)
二：
模版参数格式化时，可以使用特征数据库进行初始化。prompt.format(**know)
'''
'''
普通模版
将用户搜索内容格式化到提示模版中,接受任意数量的参数
'''
def makePromptFromTemplate(reqStr: str):
    template = "What is a good name for a company that makes {product}?"
    prompt = PromptTemplate.from_template(template)
    prompt.format(product=reqStr)
    return
'''
聊天模版
提示数组：格式化后的提示词，角色信息
'''
def makePromptfromMessage(reqStr: str):
    template = "You are a helpful assistant that translates {input_language} to {output_language}."
    sys_message_prompt_template = SystemMessagePromptTemplate.form_message(template)

    human_template = "{text}"
    hunman_prompt_template = HumanMessagePromptTemplate.from_template(template)

    parmas: list = [sys_message_prompt_template,hunman_prompt_template]
    chat_prompt = ChatPromptTemplate.from_messages(parmas)

    # 将用户输入格式化输入到模版中
    chat_prompt.format_messages(input_language="English", output_language="French", text="I love programming.")

# 调用特征库完成模版参数格式化
def makePromptFomatFromKnow():
    template = "You are a helpful assistant that translates {input_language} to {output_language}."
    prompt = PromptTemplate.from_template(template)
    prompt_template = prompt_fromat_Feats.FeastPromptTemplate(input_variables=["driver_id"])
    prompt_template.fromat(driver_id=1001)
